using System;
using System.Web.UI;
using System72.NTextile;
namespace NTextileUsage
{
    public partial class _Default : Page
    {
        #region Protected Methods

        protected void Page_Load(object sender, EventArgs e)
        {
            initializePreview();
        }

        protected void btnTextToHTML_Click(object sender, EventArgs e)
        {
            TextileParser parser = new TextileParser(txtTextToFormat.Text);
            // Add supported Alignments
            parser.AllowLeftAlignment = true;
            parser.AllowRightAlignment = true;
            parser.AllowCenterAlignment = true;
            parser.AllowJustifyAlignment = true;
            //Add supported Attribute operations
            parser.AllowClassAttribute = true;
            parser.AllowClassIdAttribute = true;
            parser.AllowIdAttribute = true;
            parser.AllowStyleAttribute = true;
            parser.AllowLanguageAttribute = true;
            //Add supported Phrase Modifiers
            parser.AllowCitationModifier = true;
            parser.AllowBoldModifier = true;
            parser.AllowDeletedTextModifier = true;
            parser.AllowEmphasisModifier = true;
            parser.AllowInsertedTextModifier = true;
            parser.AllowSpanModifier = true;
            parser.AllowStrongModifier = true;
            parser.AllowSubscriptModifier = true;
            parser.AllowSuperscriptModifier = true;
            parser.AllowItalicsModifier = true;
            //Add supported Block Modifiers
            parser.AllowHeaderModifier = true;
            parser.AllowBlockquoteModifier = true;
            parser.AllowParagraphModifier = true;
            parser.AllowBlockcodeModifier = true;
            parser.AllowPreformatModifier = true;
            parser.AllowNoTextileModifier = true;
            //Add supported Punctuation Modifiers last to process after everything else has been parsed
            parser.AllowCopyrightPunctuation = true;
            parser.AllowTrademarkPunctuation = true;
            parser.AllowRegisteredPunctuation = true;
            parser.AllowEmDashPunctuation = true;
            parser.AllowEnDashPunctuation = true;
            parser.AllowDimensionPunctuation = true;
            parser.AllowDoubleQuotesPunctuation = true;
            parser.AllowSingleQuotesPunctuation = true;
            parser.AllowEllipsesPunctuation = true;

            //Add other supported Modifiers
            parser.AllowNumericListModifier = true;
            parser.AllowBulletedListModifier = true;
            parser.AllowLinkModifier = true;
            parser.AllowFootnoteModifier = true;
            parser.AllowFootnoteRefModifier = true;
            parser.AllowImageModifier = true;
            parser.AllowAcronymModifier = true;
            parser.AllowImageLinkModifier = true;

            //Get the formatted XHTML: Parse!!!!
            txtHTML.Text = parser.GenerateXHTML();
            lblPreview.Text = txtHTML.Text;
        }

        protected void m_lnkSampleText_Click(object sender, EventArgs e)
        {
            txtTextToFormat.Text =
                String.Format("{1}{0}{2}{0}{3}{0}{4}", Environment.NewLine + Environment.NewLine,
                              loadMiscellaneousText(), loadPhraseModifierText(), loadBlockModifierText(),
                              loadPunctuationText());
        }

        #endregion

        #region Private Methods

        private void initializePreview()
        {
            lblPreview.Text = "Preview will be shown here";
            txtHTML.Text = String.Empty;
        }

        private string loadPhraseModifierText()
        {
            return String.Format
                (
                "{0}{3}{1}{2}{0}{4}{1}{2}{0}{5}{1}{2}{0}{6}{1}{2}{0}{7}{1}{2}{0}{8}{1}{2}{0}{9}{1}{2}{0}{10}{1}{2}{0}{11}{1}{2}{0}{12}{1}{2}",
                "This is an example of ",
                " text", Environment.NewLine + Environment.NewLine,
                "_(big)emphasis_",
                "*(#s1)strong*",
                "??citation??",
                "-{color:red}deleted text-",
                "+{color:green}inserted text+",
                "^superscript^",
                "~subscript~",
                "%[fr]span%",
                "__italics__",
                "**bold**"
                );
        }

        private string loadBlockModifierText()
        {
            return String.Format
                    (
                    "{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{8}{0}{10}{0}{11}{0}{12}{0}{13}{0}{14}",
                    Environment.NewLine + Environment.NewLine,
                    "Footnote covered elsewhere[1]",
                    "h1. Heading 1",
                    "h2. Heading 2",
                    "h3. Heading 3",
                    "h4. Heading 4",
                    "h5. Heading 5",
                    "h6. Heading 6",
                    "Any Old Text",
                    "bq. A block Quotation",
                    "bc. This is block code.\n<script>\n// a Javascript example\nalert(\"Hello World\");\n</script>",
                    "pre. This is identical to above.\n\"Hello there\"\n Except for code tags",
                    "p. This is a test of paragraph.\n Should be wrapped in p tags.",
                    "notextile. Well, that went well. How about we insert an <a href=\"http://www.saipanyam.net\" title=\"watch out\">old-fashioned hypertext link</a>? Will the quote marks in the tags get messed up? No!",
                    "fn1. Infact down here!"
                    );
        }

        private string loadPunctuationText()
        {
            return String.Format
                    (
                    "{4}{1}{4}{0}{2}{0}{3}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{10}{0}{11}{0}",
                    Environment.NewLine + Environment.NewLine,
                    "Double Quotes",
                    "'Single Quotes'",
                    "it's a test of aphostrophe",
                    "\"",
                    "em -- dash",
                    "en - dash",
                    "2 x 4",
                    "foo(tm)",
                    "foo(r)",
                    "foo(c)",
                    "p. It was a dark windy night. People were hurrying to get back into the warmth of their homes. Meanwhile..."
                    );
        }

        private string loadMiscellaneousText()
        {
            return String.Format
                    ("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}",
                     Environment.NewLine + Environment.NewLine,
                     "ABC(Always Be Clear)- example of Acronym",
                     "!Images/Sai.jpg(Yours truly!)!",
                     "\"My Website(Sai Panyam)\":http://www.saipanyam.net",
                     "!Images/Sai.jpg(Yours truly again!)!:http://www.saipanyam.net",
                     "#{color:red} The time is now" + Environment.NewLine
                     + "# The time is not later" + Environment.NewLine
                     + "# The time is not yesterday" + Environment.NewLine
                     + "#{color:green} We must act",
                     "* The time is past now" + Environment.NewLine
                     + "*{color:blue} The time was later" + Environment.NewLine
                     + "* The time was yesterday" + Environment.NewLine
                     + "*{color:brown} We should have acted"
                    );
        }
        #endregion


    }
}
